package com.mes.material.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.mes.common.core.utils.poi.ExcelUtil;
import com.mes.common.core.web.controller.BaseController;
import com.mes.common.core.web.domain.AjaxResult;
import com.mes.common.core.web.page.TableDataInfo;
import com.mes.common.log.annotation.Log;
import com.mes.common.log.enums.BusinessType;
import com.mes.common.security.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.mes.material.domain.MaterialStock;
import com.mes.material.service.IMaterialStockService;

/**
 * 库存管理Controller
 * 
 * @author itflash
 * @date 2025-02-27
 */
@RestController
@RequestMapping("/material/stock")
public class MaterialStockController extends BaseController
{
    @Autowired
    private IMaterialStockService materialStockService;

    /**
     * 查询库存管理列表
     */
    @RequiresPermissions("material:stock:list")
    @GetMapping("/list")
    public TableDataInfo list(MaterialStock materialStock)
    {
        startPage();
        List<MaterialStock> list = materialStockService.selectMaterialStockList(materialStock);
        return getDataTable(list);
    }

    /**
     * 导出库存管理列表
     */
    @RequiresPermissions("material:stock:export")
    @Log(title = "库存管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MaterialStock materialStock)
    {
        List<MaterialStock> list = materialStockService.selectMaterialStockList(materialStock);
        ExcelUtil<MaterialStock> util = new ExcelUtil<MaterialStock>(MaterialStock.class);
        util.exportExcel(response, list, "库存管理数据");
    }

    /**
     * 获取库存管理详细信息
     */
    @RequiresPermissions("material:stock:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(materialStockService.selectMaterialStockById(id));
    }

    /**
     * 新增库存管理
     */
    @RequiresPermissions("material:stock:add")
    @Log(title = "库存管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MaterialStock materialStock)
    {
        return toAjax(materialStockService.insertMaterialStock(materialStock));
    }

    /**
     * 修改库存管理
     */
    @RequiresPermissions("material:stock:edit")
    @Log(title = "库存管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MaterialStock materialStock)
    {
        return toAjax(materialStockService.updateMaterialStock(materialStock));
    }

    /**
     * 删除库存管理
     */
    @RequiresPermissions("material:stock:remove")
    @Log(title = "库存管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(materialStockService.deleteMaterialStockByIds(ids));
    }
}
